package fhjoanneum.itm11.antesk.simplehack;
import java.io.*;

public class Config
{
	// Members -----------------------------------------------------------
	private final String str_file_name;
  private final String cur_dir;
  private int[] config;

  // Constructor -------------------------------------------------------
  Config()
  {
  	this("config.txt");
  }
  
  // Copy Constructor --------------------------------------------------
  Config(String filename)
  {
  	this.str_file_name = filename;
  	this.cur_dir = System.getProperty("user.dir");
  	this.config = new int[100];
  }
  
  // -------------------------------------------------------------------
  public String getCurDir(){return this.cur_dir;}
  public int getConfig(int index){return this.config[index];}
  
  public void readFile()
  {
  	try
    {
      FileInputStream fin = new FileInputStream(cur_dir + "\\" + 
      		str_file_name);
      DataInputStream din = new DataInputStream(fin);
      
      int char_counter = 0;
      int ch = 0;
      
      // Reads the file until the length of config[] is reached
      do
      {
      	ch = din.read();
      	if(ch != 13 && ch != 10) // Logic: (~a & ~b) for break chars
      	{
      		this.config[char_counter] = ch;
      		char_counter++;
      	}
      }
      while(char_counter < this.config.length);
             
      din.close();
     }
    catch(FileNotFoundException fe)
    {
      System.out.println("FileNotFoundException : " + fe);
    }
    catch(IOException ioe)
    {
      System.out.println("IOException : " + ioe);
    }
  }
}
